<?php

/*

Fake id class, to render catalogs, gets $&cid from get and returns master-parent id (pre 0, not 0)


*/

Class draw_catalogs extends CatalogPage {

var $_core;
var $_render;
var $_db;


function draw_catalogs(&$core, &$render, &$db) {

$this->_core = $core;
$this->_render = $render;
$this->_db = $db;


}

function get_main_parent_id ($cid) {
	$p_id = 0;

	$sql= "select parent_id from catalog where catalog_id='".Str2db($cid)."'";
	$p_id = $this->_db->getOne($sql);

//debug($p_id);die();
	

	while ($p_id != 0) {
	$sql= "select catalog_id, parent_id from catalog where catalog_id='".Str2db($p_id)."'";
	$r = $this->_db->getRow($sql);
	$p_id = $r['parent_id'];
	$c_id = $r['catalog_id']; 
	//debug($p_id);
	};
	if ($c_id == '')
	return($cid);
	else    {
	return($c_id);
		}					
				   }

					}




?>